package com.jml.xxljob001;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.core.util.ShardingUtil;


@Component
public class MyJob {

    @Value("${xxl.job.executor.port}")
    private String executorPort;

    @XxlJob("demoMyJob")
    public ReturnT<String> demoMyJob(String value) {
        ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
        XxlJobLogger.log("分片参数：当前分片序号 = {}, 总分片数 = {}", shardingVO.getIndex(), shardingVO.getTotal());
        System.out.println("分片序号：" + shardingVO.getIndex() + ",分片总数" + shardingVO.getTotal() + "，时间" + System.currentTimeMillis());
        System.out.println("demoMyJob:定时任务触发：" + value + ",端口号为:" + executorPort);
        return ReturnT.SUCCESS;
    }

    @XxlJob("userMyJob")
    public ReturnT<String> userMyJob(String value) {
        System.out.println("userMyJob:定时任务触发：" + value);
        return ReturnT.SUCCESS;
    }
}
